package com.hopu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class ViewController {

    @RequestMapping({"/","index"})
    private String index(){
        return "index.jsp";
    }

    @RequestMapping("main")
    private String main(){
        return "main/main";
    }

    @RequestMapping("/loginout")
    private String loginout(HttpSession session){
        session.removeAttribute("empLog");
        return "redirect:/";
    }

    @GetMapping("/redirect")
    private String page(@RequestParam String page, HttpServletRequest request){
        String pid = request.getParameter("pid");
        String eid = request.getParameter("eid");
        String aid = request.getParameter("aid");
        String sid = request.getParameter("sid");
        String jid = request.getParameter("jid");
        String hid = request.getParameter("hid");
        String cid = request.getParameter("cid");
        String mid = request.getParameter("mid");
        String yid = request.getParameter("yid");
//        System.out.println(pid);
        request.getSession().setAttribute("pid", pid);
        request.getSession().setAttribute("eid", eid);
        request.getSession().setAttribute("aid", aid);
        request.getSession().setAttribute("sid", sid);
        request.getSession().setAttribute("jid", jid);
        request.getSession().setAttribute("hid", hid);
        request.getSession().setAttribute("cid", cid);
        request.getSession().setAttribute("mid", mid);
        request.getSession().setAttribute("yid", yid);
//        System.out.println("aid="+aid);
        return page;
    }
}
